package com.heriparid.fragmentinjection;

import java.util.Arrays;
import java.util.List;

import android.app.Activity;
import android.app.Application;
import android.util.Log;
import butterknife.Views;

import com.heriparid.fragmentinjection.modules.ActivityModule;
import com.heriparid.fragmentinjection.modules.AndroidModule;

import dagger.ObjectGraph;

public class App extends Application {
	
	
	private static final String TAG = App.class.getSimpleName();
	private ObjectGraph mGraph;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		mGraph = ObjectGraph.create(getModules().toArray());	
	}
	
	protected List<Object> getModules(){
		return Arrays.asList(
			new AndroidModule(App.this), 
			new ActivityModule()
		);
	}
	
	public void injectMembers(Object instance){
		Log.v(TAG, "injecting a " + instance.toString());
		
		mGraph.inject(instance);
		
		if(instance instanceof Activity){
			Log.v(TAG, "add view injection for " + instance.toString());
			Views.inject((Activity) instance);
		}
		
	}

}